package com.tarena.lbs.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

@Configuration
public class BlacklistConfig {

    // 模拟从文件加载黑名单，实际也可从数据库、Nacos 配置中心等扩展
    @Bean
    public Set<String> blacklistUserIds() {
        Set<String> blacklist = new HashSet<>();
        ClassPathResource resource = new ClassPathResource("blacklist.txt");
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                blacklist.add(line.trim());
            }
        } catch (IOException e) {
            e.printStackTrace();
            // 实际可做更友好的异常处理，比如记录日志、返回空集合等
        }
        return blacklist;
    }
}